//-----------------------------------------------------------------------------
//	File: mgui_string.c
//	Author: xialing
//		string of mgui
//-----------------------------------------------------------------------------

#include "mgui_string.h"

//-----------------------------------------------------------------------------
//	mgui_putc - mgui put a character
//		@c: character
//-----------------------------------------------------------------------------
static void mgui_putc(char c, uint16_t x, uint16_t y)
{
	uint8_t i, j;
	uint8_t *p;
	uint16_t k;

	p = mgui_conf->font->dat + (c - 0x20) * mgui_conf->font->b;
	for (j=0,k=0; j<mgui_conf->font->h; j++) {
		for (i=0; i<mgui_conf->font->w; i++,k++) {
			if (p[k >> 3] & (1 << (k & 7))) {
				mgui_draw_pixel(x + i, y + j, 1 ^ mgui_conf->invc);
			} else {
				mgui_draw_pixel(x + i, y + j, 0 ^ mgui_conf->invc);
			}
		}
	}
}

//-----------------------------------------------------------------------------
//	mgui_puts- mgui put string
//		@s: string
//		@x: x position
//		@y: y position
//-----------------------------------------------------------------------------
void mgui_puts(char *s, uint16_t x, uint16_t y)
{
	while (*s != '\0') {
		mgui_putc(*s++, x, y);
		x += mgui_conf->font->w;
	}
}

//-----------------------------------------------------------------------------
//	mgui_puts_inv - mgui put string inverse
//		@s: string
//		@x: x position
//		@y: y position
//-----------------------------------------------------------------------------
void mgui_puts_inv(char *s, uint16_t x, uint16_t y)
{
	mgui_conf->invc ^= 1;
	while (*s != '\0') {
		mgui_putc(*s++, x, y);
		x += mgui_conf->font->w;
	}
	mgui_conf->invc ^= 1;
}
